import Vue from "vue";
import VueRouter from "vue-router";
import home from "../views/home/index.vue";
// import about from "../views/about/index.vue";

// 重复点击路由跳转报错
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};
Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "home",
    meta: { title: "home" },
    component: home,
  },
  {
    path: "/about",
    name: "about",
    meta: { title: "about" },
    // 按需加载需要 @babel/plugin-syntax-dynamic-import babel才能正确解析
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/about/index.vue"),
  },
];

const router = new VueRouter({
  mode: "hash",
  //   base: process.env.BASE_URL,
  routes,
  //   scrollBehavior() {
  //     return { x: 0, y: 0 };
  //   },
});

export default router;
